<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    .box {
      width: 120px;
      height: 120px;
      display: flex;
      position: absolute;
      left: 0;
      top: 0;
      cursor: pointer;
    }

    .content {
      width: 100px;
      height: 100px;
      border-radius: 50%;
      background-color: black;
      line-height: 100px;
      text-align: center;
      color: #fff;
      /* 图标垂直水平居中 */
      margin: auto;
    }
  </style>
  <script>
    window.onload = function () {
      var box = document.querySelector('.box');
      var content = document.querySelector('.content')
      // 鼠标按下
      box.onmousedown = function () {
        box.style.backgroundColor = '#666'
        document.onmousemove = function (e) {
          var e = e || event
          box.style.left = e.pageX - box.offsetWidth / 2 + 'px';
          box.style.top = e.pageY - box.offsetHeight / 2 + 'px';
        }
      }
      box.onmouseup = function () {
        box.style.backgroundColor = ''
        //  鼠标谈起，清空鼠标移动事件
        document.onmousemove = null;
      }
    }
  </script>
</head>

<body>
  <div class="box">
    <div class="content">图标移动</div>
  </div>
</body>

</html>